package com.apes.fn.mdm.serveTypeContrast;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ServeType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 服务类型对照表
 *      用于异业合作写入凭证时转换商品
 * @Author wuq
 * @Date 2022-1-21
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ServeTypeContrast.CONST_TABLE_NAME,
        indexes = @Index(columnList = "serve_Type, product_id, type", unique = true) )
public class ServeTypeContrast extends Model {
    public static final String CONST_TABLE_NAME = "mas_Serve_Type_Contrast";

    @Id
    @Column(name = "id", length = 6)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "服务类型对照表")
    @Comment("编号")
    private String id;

    @Column(name = "type", length = 10)
    @Comment("类型")
    private String type; // 异业：crossIC，  e保养：insuranceDiscount

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "serve_Type", referencedColumnName = "id", nullable = false)
    @Comment("服务类型")
    public ServeType serveType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    @Comment("商品")
    private Product product;

    @Column(name = "valid")
    @Comment("有效标记")
    private boolean valid = true; //有效
}
